package com.zj.android.model

import android.app.Application
import android.content.pm.PackageManager
import android.view.View
import androidx.annotation.NonNull
import com.zj.android.MyApplication
import com.zj.android.activity.CameraActivity
import com.zj.android.activity.NavigationActivity
import com.zj.android.activity.PagingActivity
import com.zj.common.expand.requestFullCallback
import com.zj.common.expand.toast
import com.zj.common.utils.PermissionConstants
import com.zj.common.viewmodel.BaseViewModel

class MainViewModel(@NonNull application: Application) : BaseViewModel(application) {

    val main = View.OnClickListener {

        //viewModelScope.retrofit<ArticleBean> {
        //    api { getApplication<MyApplication>().api.getArticle(1) }
        //    onSuccess {
        //        DebugUtils.printfError("请求成功")
        //    }
        //    onFailed { _, _ ->
        //        DebugUtils.printfError("请求失败")
        //    }
        //    onComplete {
        //        DebugUtils.printfError("请求完成")
        //    }
        //}


    }
    val goCameraX: View.OnClickListener
        get() {
            return View.OnClickListener {
                if (getApplication<MyApplication>().packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)) {
                    requestFullCallback(PermissionConstants.CAMERA, onGranted = {
                        goActivity(CameraActivity::class.java)
                    }, onDenied = {
                        getApplication<MyApplication>().toast("同意后才可用相机权限")
                    })
                }
            }
        }

    val goPaging: View.OnClickListener
        get() {
            return View.OnClickListener {
                goActivity(PagingActivity::class.java)
            }
        }
    val goNavigation: View.OnClickListener
        get() {
            return View.OnClickListener {
                goActivity(NavigationActivity::class.java)
            }
        }


}